package c.x.jy.admin.controller;

import java.util.Arrays;
import java.util.Map;

import c.x.jy.common.annotation.IntoSet;
import c.x.jy.dao.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import c.x.jy.dao.entity.MemberCashApplyEntity;
import c.x.jy.service.service.MemberCashApplyService;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;



/**
 * 会员提现申请表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-25 10:47:37
 */
@RestController
@RequestMapping("member/membercashapply")
public class MemberCashApplyController extends AbstractController {
    @Autowired
    private MemberCashApplyService memberCashApplyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("member:membercashapply:list")
    @IntoSet(Includefields={"applyUsername","checkUsername","cashUsername"})
    public R list(@RequestParam Map<String, Object> params){
     	if(getUser().getBusinessId()>0) {
    		params.put("businessId", getUser().getBusinessId());
    	}
        PageUtils page = memberCashApplyService.queryPage(params);

        return R.put(page);
    }
    /**
     * 列表 for WEB
     */

    @RequestMapping("/listforweb")
    @RequiresPermissions("member:membercashapply:list")
    @IntoSet(Includefields={"applyUsername","checkUsername","cashUsername"})
    public R listforweb(@RequestParam Map<String, Object> params){
        if(getUser().getBusinessId()>0) {
            params.put("businessId", getUser().getBusinessId());
        }
        PageUtils page = memberCashApplyService.queryPageforWeb(params);

        return R.put(page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("member:membercashapply:info")
    public R info(@PathVariable("id") Long id){
		MemberCashApplyEntity memberCashApply = memberCashApplyService.getById(id);

        return R.put(memberCashApply);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("member:membercashapply:save")
    public R save(@RequestBody MemberCashApplyEntity memberCashApply){
		memberCashApplyService.save(memberCashApply);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("member:membercashapply:update")
    public R update(@RequestBody MemberCashApplyEntity memberCashApply){
		memberCashApplyService.updateById(memberCashApply);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("member:membercashapply:delete")
    public R delete(@PathVariable("id") Long id){
		memberCashApplyService.removeByIds(Arrays.asList(id));

        return R.ok();
    }


    /**
     * 通过审核
     */
    @RequestMapping("/pass/{id}")
    @RequiresPermissions("member:membercashapply:update")
    public R pass(@PathVariable("id") Long id){
//        teacherService.removeByIds(Arrays.asList(id));

        SysUserEntity checkUser = getUser();
        memberCashApplyService.passById(id,checkUser);
        return R.ok();
    }
    /**
     * 驳回
     */
    @RequestMapping("/reject/{id}")
    @RequiresPermissions("member:membercashapply:update")
    public R reject(@PathVariable("id") Long id){
//        teacherService.removeByIds(Arrays.asList(id));

        SysUserEntity checkUser = getUser();
        memberCashApplyService.rejectById(id,checkUser);
        return R.ok();
    }
    /**
     * 支付
     */
    @RequestMapping("/pay/{id}")
    @RequiresPermissions("member:membercashapply:update")
    public R pay(@PathVariable("id") Long id){
//        teacherService.removeByIds(Arrays.asList(id));

        SysUserEntity checkUser = getUser();
        memberCashApplyService.payById(id,checkUser);
        return R.ok();
    }
}

